const assert = require("assert");
const Ret = require("../src/ret.js");

describe("ret.js", () => {
  describe("new()", () => {
    it("ok", () => {
      let ret = new Ret(true).setData({ name: "good" });
      console.log(ret)
      assert(ret.getJson().data.name, "good");
    });
    it("mutli params", () => {
      let ret = new Ret(false, "失败啦", Ret.CODE_ROLE);
      assert(ret.getJson().code, Ret.CODE_ROLE);
    });
  });

  describe("filter()", () => {
    it("ok", () => {
      let ret = new Ret(true)
        .setData({
          id: 1,
          name: "good",
          products: [
            { id: 1, name: "p1" },
            { id: 2, name: "p2" },
          ],
        })
        .filter(["name", "products"]);
      console.log(ret.toString());
      assert(ret.toJson().data.name, "good");
    });
  });
});
